package com.fantastic.web.ex;

import com.fantastic.common.exception.AuthException;
import com.fantastic.common.exception.LoginException;
import com.fantastic.common.exception.RegisterException;
import com.fantastic.common.result.ResultData;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author: rxx
 * @since: 2024/5/22 16:08
 * @description: 登录时产生的异常
 */
//标明为控制全局异常处理器
@RestControllerAdvice
//标明为响应体
public class GlobalExceptionAdvice {

    /**
     * 登录失败
     *
     * @return 返回状态对象
     * @ExceptionHandler() 标明controller层只要有方法抛出这个异常就会进入到个方法对异常进行处理
     * @ResponseBody 返回响应体，自动json
     */
    @ExceptionHandler(LoginException.class)
    public ResultData loginExceptionMethod(LoginException e) {
        return new ResultData(e.getResponseStatusEnum());
    }

    /**
     * 注册失败。可能是注册信息不完整或是服务器异常
     *
     * @return 返回状态对象
     */
    @ExceptionHandler(RegisterException.class)
    public ResultData registerExceptionMethod(RegisterException e) {
        return new ResultData(e.getResponseStatusEnum());
    }

    /**
     *Token校验异常
     * @param e
     * @return
     */
    @ExceptionHandler(AuthException.class)
    public ResultData registerExceptionMethod(AuthException e) {
        return new ResultData(e.getResponseStatusEnum());
    }

}
